﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Rose.Models.AlbumModel>>" %>

  <div id="albumlist">
   
    <% foreach (var item in Model) { %>
        <div class="album">
               <div class="albumimage">
               <p>

             <a id="<%=item.AlbumId %>" href="<%=item.ImagePath %>" rel="prettyPhoto[<%=item.AlbumId %>]" title="<%=item.Title %>"><img src="/Image/GetImage?image=<%=item.ImagePath %>"/></a>
            
               </p>

               </div>

              <div class="albumdescription">
               <p><a>  <%= item.Title %></a>(<%= item.PhotoCount %>)</p>


               <p>
               <%if (item.IsOnlyForFriend == 0)
                 { %>
                 <a><img src="../../Content/Images/extra/album/encrypt.png" alt="隐私" title="隐私" /></a>
               <%}
                 else if (item.IsOnlyForFriend == 1)
                 { %>
                 <a><img src="../../Content/Images/extra/album/friends_only.png" alt="仅好友可见" title="仅好友可见" /></a>
               <%}
                 else
                 {%>
                 <a><img src="../../Content/Images/extra/album/friends_only.png" alt="公开" title="公开" /></a>
               <%} %>

                <a class="edit pointer" onclick="EditAlbum(this);"dataIsOnly="<%=item.IsOnlyForFriend %>" dataTitle="<%=item.Title %>" dataId="<%=item.AlbumId%>" dataImagePath="<%=item.ImagePath %>" >编辑</a>
                <a class="edit pointer" onclick="UpPhoto(this);" data="<%=item.AlbumId %>">上传</a>

               </p>
              </div>
               
        </div>

    <% } %>


</div> <%--end of albumlist--%>

   <script type="text/javascript">
       function EditAlbum(e) {

           var imagepath = $(e).attr('dataImagePath');
           var title = $(e).attr('dataTitle');
           var isonly = $(e).attr('dataIsOnly');
           var albumid = $(e).attr('dataId');
           
           var content;
           if (isonly == 0)
           { content = '<div class="d_album"><div class="albumdialog"><a><img src="/Image/GetImage?image=' + imagepath + '"  /></a></div> <div class="albumdescription"><p>相册标题:<input id="title_a" type="text" value="' + title + '"></p><p>权限设置:<input type="radio" value="0" checked="checked" name="a" >隐私<input type="radio" value="1" name="a">仅朋友可见<input type="radio" name="a" value="2">公开</p><p><input type="button" id="savealbum" value="保存"></p> </div></div>'; }
           else if (isonly == 1)
           { content = '<div class="d_album"><div class="albumdialog"><a><img src="/Image/GetImage?image=' + imagepath + '"  /></a></div> <div class="albumdescription"><p>相册标题:<input id="title_a" type="text" value="' + title + '"></p><p>权限设置:<input type="radio" value="0" name="a" >隐私<input type="radio" value="1" checked="checked" name="a">仅朋友可见<input type="radio" name="a" value="2">公开</p><p><input type="button" id="savealbum" value="保存"></p> </div></div>'; }
          else 
           { content = '<div class="d_album"><div class="albumdialog"><a><img src="/Image/GetImage?image=' + imagepath + '"  /></a></div> <div class="albumdescription"><p>相册标题:<input id="title_a" type="text" value="' + title + '"></p><p>权限设置:<input type="radio" value="0" name="a" >隐私<input type="radio" value="1" name="a">仅朋友可见<input type="radio" name="a" checked="checked" value="2">公开</p><p><input type="button" id="savealbum" value="保存"></p> </div></div>'; }
           var dialogname = 'albumdialog';
           
           $('body').append('<div id="' + dialogname + '">' + content + '</div>');
           $('#' + dialogname).dialog({ autoOpen: true, width: 800, height: 400, resizable: false, modal: true });
           $('#savealbum').click(function () {
               var title_a = $('#title_a').val();
               var isonly_a = 2;
               isonly_a = $('.d_album').find(':checked').val();
               $.ajax({
                   url: '/Album/ChangeAlbum',
                   type: 'POST',
                   data: { title: title_a, isOnlyForFriend: isonly_a, albumId: albumid },
                   success: function (data) { cAlert(data); },
                   error: function () { Error(); }
               });
               $('#' + dialogname).remove();


           });

        }
   
   </script>
   <style type="text/css">
        .d_album { width:500px;margin:auto; text-align:center;}
        
   </style>

   <script type="text/javascript">
       function UpPhoto(e) {
           var albumid = $(e).attr('data');
          
           var content = '<div id="iframe" style="margin:auto;width:520px;"><iframe  width="500px" height="500px"  src="/Album/UploadPhoto?albumId=' + albumid + '"></iframe></div>';
           var dialogname = 'iframedialog';
           $('body').append('<div id=' + dialogname + '>' + content + '</div>');

           $('#' + dialogname).dialog({ autoOpen: true, width: 800, height: 600, resizable: false, modal: true, close: function () { $('#' + dialogname).remove(); } });

       }
   
   </script>